package com.ylkj.user.services.impl;

import com.ylkj.core.page.IGenericPage;
import com.ylkj.user.dao.UserDao;
import com.ylkj.user.model.User;
import com.ylkj.user.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public int save(User ob) throws Exception {
        return userDao.save(ob);
    }

    @Override
    public User getById(Long id) {
        return userDao.getById(id);
    }

    @Override
    public int update(User ob) throws Exception {
        return userDao.update(ob);
    }

    @Override
    public int deleteById(Long id) throws Exception {
        //清除用户角色关联
        userDao.deleteById(id);
        return 1;
    }

    @Override
    public IGenericPage<User> findPageBy(User param, int pageNo, int pageSize, String sort, String dir) {
        return userDao.findPageBy(param, pageNo, pageSize, sort, dir);
    }

    @Override
    public Integer getCountBy(User param) {
        return userDao.getCountBy(param);
    }

    @Override
    public List<User> findListBy(User param, String sort, String dir) {
        return userDao.findListBy(param, sort, dir);
    }

    @Override
    public List<Object> findListByMapData(User param,String sort, String dir) {
        List returnList= new ArrayList();

        List list0= new ArrayList();
        List list1= new ArrayList();
        List list2= new ArrayList();
        List list3= new ArrayList();
        List list4= new ArrayList();
        List list5= new ArrayList();

        List<User> list = userDao.findListBy(param,sort, dir);
        for (User user :list  ) {
            List tmpList = new ArrayList();
            tmpList.add(0,user.getJ());
            tmpList.add(1,user.getW());
            tmpList.add(2,1);
            tmpList.add(3,user);
            if(user.getType().equals("党政系统人才")){
                list0.add(tmpList);
            }else if(user.getType().equals("军队系统人才")){
                list1.add(tmpList);
            }else if(user.getType().equals("科研创新人才")){
                list2.add(tmpList);
            }else if(user.getType().equals("企业管理人才")){
                list3.add(tmpList);
            }else if(user.getType().equals("海外学子")){
                list4.add(tmpList);
            }else if(user.getType().equals("其他")){
                list5.add(tmpList);
            }
        }
        returnList.add(0,list2);
        returnList.add(1,list3);
        returnList.add(2,list1);
        returnList.add(3,list4);
        returnList.add(4,list5);
        returnList.add(5,list0);
        return returnList;
    }
}
